package com.umgsai.thread.thread52;

import java.util.concurrent.locks.ReentrantLock;

/**
 * getHoldCount()方法查询当前线程保持此锁定的个数
 * 也就是调用()方法的次数
 */
public class Service {
	private ReentrantLock lock = new ReentrantLock();
	public void serviceMethod1() {
		try {
			lock.lock();
			System.out.println("serviceMethod1 getHoldCount=" + lock.getHoldCount());//1
			serviceMethod2();
		} finally{
			lock.unlock();
		}
	}
	public void serviceMethod2() {
		try {
			lock.lock();
			System.out.println("serviceMethod2 getHoldCount=" + lock.getHoldCount());//2
		} finally{
			lock.unlock();
		}
	}
	public static void main(String[] args) {
		Service service = new Service();
		service.serviceMethod1();
	}
}
